(() => {
	let page = 1;
	let ele = {};
	ele.list = $('#list');
	ele.more = $('#more');
	ele.empty = $('#empty');

	ele.info = $('#info');


	// 各挡位零钱列表
	getInfo()
	function getInfo() {
		let token = getCookie("token");
		let userid = getCookie("userid");
		ajax({
			url: API_PATH.GELINGQIANRENSHU,
			method: 'GET',
			header: {
				Authorization: token
			},
			success: res => {
				if (res.code == 1) drawPropList(res.data);
				else openTips(res.msg);
			}
		});
	}
	function drawPropList(data) {
		let html = '';
		for (let i = 0; i < data.length; i++) {
			let lv = data[i];
			html += '<div class="link">' +
				'<p class="lin1">' + lv.money + '零钱</p>' +
				'<p class="lin2">开出次数：' + lv.num + '</p>' +
				'</div>'

		}
		ele.info.innerHTML = html;
	}

	// 获取大奖记录
	getDetail(page);
	function getDetail(page) {
		ele.more.innerText = '加载中...';
		let token = getCookie("token");
		let userid = getCookie("userid");
		ajax({
			url: API_PATH.GETHUODEJILU,
			method: 'GET',
			header: {
				Authorization: token
			},
			data: {
				page: page
			},
			success: res => {
				if (res.code == 1) {
					let detail = res.data.data;
					if (detail.length === 0) {
						page = 0;
						ele.more.style.display = "none";
						ele.empty.style.display = "block";
					} else {
						drawDetail(detail);
						page++;
						if (page > res.data.last_page) {
							ele.more.innerText = '没有更多了';
							ele.more.onclick = null;
						}
						else {
							ele.more.innerText = '加载更多';
							ele.more.onclick = () => getDetail(page);
						}
					}
				}
				else openTips(res.msg);
			}
		});
	}
	function drawDetail(data) {
		if (data.length === 0) {
			page = 0;
			ele.more.style.display = "none";
			ele.empty.style.display = "block";
		} else {
			let str = '';
			for (let i = 0; i < data.length; i++) {
				let invite_code = data[i].agent ? data[i].agent.invite_code : '未知'
				str += '<div class="item">' +
					'<p class="title">恭喜ID:' + invite_code + ' 开启' + 'VIP盲盒' + '获得' + data[i].money + '零钱</p>' +
					'</div>'
			}
			ele.list.innerHTML += str;
		}
	}
})();
